package com.ctg.itrdc.imageconsole.data.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.ctg.itrdc.imageconsole.data.dao.IDockerMicroUserDao;
import com.ctg.itrdc.imageconsole.data.entity.user.DockerMicroUser;
import com.ctg.itrdc.paspsdk.data.dao.impl.BaseDaoImpl;

@Component("dockerMicroUserDao")
public class DockerMicroUserDaoImpl extends BaseDaoImpl implements IDockerMicroUserDao{

	@Override
	public DockerMicroUser selectById(Long id) {
		DockerMicroUser microUser = new DockerMicroUser();
		microUser.setId(id);
		return super.selectByPrimaryKey(microUser);
	}

	@Override
	public void deleteById(Long id) {
		DockerMicroUser microUser = new DockerMicroUser();
		microUser.setId(id);
		super.deleteByPrimaryKey(microUser);
	}

	@Override
	public DockerMicroUser selectByCode(String code) {
		DockerMicroUser microUser = new DockerMicroUser();
		microUser.setCode(code);
		List<DockerMicroUser> users = super.selectByExample(microUser);
		if(users.size() > 1)
			throw new RuntimeException(String.format("user %s is not unique in docker_micro_user", code));
		return users.size() == 0 ? null : users.get(0);
	}

	@Override
	public DockerMicroUser selectBySysUserId(Long sysUserId) {
		DockerMicroUser microUser = new DockerMicroUser();
		microUser.setSysUserId(sysUserId);
		List<DockerMicroUser> users = super.selectByExample(microUser);
		return users.size() == 0 ? null : users.get(0);
	}

	

	
	
	
}
